

class EmployeeController extends BaseController{
    def beforeInterceptor = [action:this.auth, except:['applicationFinished','applicationApplicant','checkCivicNumber','createApplicant','sendCourse','sendSchedule','application','applicationEmployee']]
    
    def index = { redirect(action:list,params:params) }

    // the delete, save and update actions only accept POST requests
    static allowedMethods = [delete:'POST', save:'POST', update:'POST']

    
    def list = {
        params.max = Math.min( params.max ? params.max.toInteger() : 10,  100)
        def access = session.access
        access.refresh()
        def listEmpl = access.getList("employee")
        [ employeeInstanceList:listEmpl , employeeInstanceTotal: listEmpl.count()]
    }

    def show = {
        def employeeInstance = DBConnection.getEmployee( params.id )
        def access = session.access
        def ajaxCall = params.ajaxCall;
        access.refresh()
        
        if(!employeeInstance) {
            flash.message = "Employee not found"
            redirect(action:list)
        }
        else {
            if(employeeInstance.hiredBy){
                if(!access.checkAccess(session.mode, "employee", "show", employeeInstance.hiredBy.id)){
                    flash.message="Missing authorization!"
                    redirect(action:list)
                }
            }
            ArrayList a = employeeInstance.listOfProjects();                        //A list of whoas for this year
            Integer actualHours = employeeInstance.actualWorkingHoursPerYear()         //Can skip this and use employeeInstance.actualWorkingHoursPerYear() instead
            int nbProjects = 0;
            int nbCourses = 0;
            for(Whoa w in a){
                if(w.forCourse()){
                    nbCourses++;
                }
                else{
                    nbProjects++;
                }
            }
            if(ModeAccess.isAvailableInCurrentMode(session.mode,employeeInstance.mode)){
                // If the employee mode corresponds to the current mode
                return [ 
                    employeeInstance : employeeInstance,
                    whoaList : a,
                    actualHours : actualHours ,
                    ajaxCall : ajaxCall,
                    nbProjects : nbProjects,
                    nbCourses : nbCourses
                ]
            }
            else{
                flash.message = "Employee not accessible in current mode"
                redirect(action:list)
            }
        }
    }

    def delete = {
        def access=session.access
        access.refresh()

        def employeeInstance = DBConnection.getEmployee( params.id )
        if(employeeInstance) {
            if(employeeInstance.hiredBy){
                
                if(!access.checkAccess(session.mode, "employee", "delete", employeeInstance.hiredBy.container.id)){
                    
                    flash.message="Missing authorization!"
                    redirect(action:list)
                    return
                }
            }
            try {
                DBConnection.deleteEmployee(employeeInstance.id)
                session.modified = true //to show popup window
                flash.message = "Employee ${employeeInstance} deleted"
                redirect(action:list)
            }
            catch(org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "Employee ${employeeInstance} could not be deleted"
                redirect(action:show,id:params.id)
            }
        }
        else {
            flash.message = "Employee not found"
            redirect(action:list)
        }
    }

    def edit = {
        def access = session.access
        access.refresh()
        session.proId=params.id
        def employeeInstance = DBConnection.getEmployee( params.id )

        if(!employeeInstance) {
            flash.message = "Employee not found"
            redirect(action:list)
        }
        else {
            if(employeeInstance.hiredBy){
                if(!access.checkAccess(session.mode, "employee", "edit", employeeInstance.hiredBy.id)){
                    flash.message="Missing authorization!"
                    redirect(action:show, id:params.id)
                }
            }
             if(ModeAccess.isAvailableInCurrentMode(session.mode,employeeInstance.mode)){
                // If the employee mode corresponds to the current mode
               return [ employeeInstance : employeeInstance, areas : session.access.getList("area") ]

            }
            else{
                flash.message = "Employee not accessible in current mode"
                redirect(action:list)
            }
            
        }
    }

    def update = {

        //Check that date of birth is correct
        if(params.dob_month.equals("4")||params.dob_month.equals("6")||params.dob_month.equals("9")||params.dob_month.equals("11")){
            if(params.dob_day.equals("31")){
                    params.dob_month = "ab"
            }
        }

        if(params.dob_month.equals("2")){ // check february month
            if(params.dob_day.equals("31")||params.dob_day.equals("30")){
                    params.dob_month = "ab"
            }
        }
        
        def employeeInstance = DBConnection.getEmployee( params.id )

        if(employeeInstance) {
            if(DBConnection.isConnectionStarted()){
                employeeInstance.properties = params
                if(!employeeInstance.hasErrors()) {
                    //from here own constraints
                    Integer wrong=0
                  //firstName

                    if(!employeeInstance.firstName){
                      employeeInstance.errors.rejectValue("firstName","employee.firstname.is.empty", "The First Name should be specified.")
                       wrong=1
                    }

                    else{ if(!(employeeInstance.firstName.matches("[a-öA-Ö ]+"))){//Ö
                     employeeInstance.errors.rejectValue("firstName","employee.firstname.is.wrong", "The First Name should only include characters from a-ö.")
                      wrong=1}}
                       //lastName
                   
                    if(!employeeInstance.lastName){
                        employeeInstance.errors.rejectValue("lastName" ,"employee.lastname.is.empty", "The Last Name should be specified.")
                         wrong=1
                    }
                     else{

                     if(!(employeeInstance.lastName.matches("[a-öA-Ö ]+"))){//Ö  employeeInstance.firstName =~ /[a-öA-Ö ]/
                      employeeInstance.errors.rejectValue("lastName","employee.lastName.is.wrong", "The Last Name should only include characters from a-ö.")
                  wrong=1
                    }
                    }
                    //street
                   if(!employeeInstance.street){
                        employeeInstance.errors.rejectValue( "street","employee.street.is.empty", "The Street should be specified.")
                       wrong=1
                    }
                   else{
                       if(!employeeInstance.street.matches("[a-öA-Ö0-9 ]+")){//Ö
                      employeeInstance.errors.rejectValue("street","employee.street.is.wrong", "The Street should only include characters from a-ö.")
                         wrong=1
                    }
                }
                    //city

                      if(!employeeInstance.city){
                        employeeInstance.errors.rejectValue( "city","employee.city.is.empty", "The City should be specified.")
                        wrong=1
                    }
                     else{
                       if(!employeeInstance.city.matches("[a-öA-Ö]+")){//Ö
                      employeeInstance.errors.rejectValue("city","employee.city.is.wrong", "The City should only include characters from a-ö.")
                        wrong=1
                    }}
                        //zipCode
                    if(!employeeInstance.zipCode){
                        employeeInstance.errors.rejectValue( "zipCode","employee.zipCode.is.empty", "The Zip Code should be specified.")
                         wrong=1
                    }
                    else{
                     if(employeeInstance.zipCode<10000 || employeeInstance.zipCode>99999){
                        employeeInstance.errors.rejectValue( "zipCode","employee.zipCode.is.not", "The Zip Code is not correct.")
                        wrong=1
                    }}
                //DOB
                if(employeeInstance.dob>new Date()){
                         employeeInstance.errors.rejectValue("dob" ,"employee.dop.is.not", "The DOB is not correct.")
                       wrong=1
                    }
                    //email
                     if(!employeeInstance.email){
                         employeeInstance.errors.rejectValue("email" ,"employee.email.is.empty", "The Email should be specified.")
                       wrong=1
                    }
                    else{
                    if(!employeeInstance.email.matches("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}")){//Ö
                           employeeInstance.errors.rejectValue("email" ,"employee.email.wrong", "The Email is not correct.")
                       wrong=1
                    }}
                    //title
                     if(!employeeInstance.title){
                        employeeInstance.errors.rejectValue( "title","employee.title.is.empty", "The Title should be specified.")
                        wrong=1
                    }
                         //salary
                         if(employeeInstance.salary==0){

                         }
                  else if(!employeeInstance.salary){
                        employeeInstance.errors.rejectValue( "salary","employee.salary.is.empty", "The Salary should be specified.")
                       wrong=1
                    }
                    else{
                         if(employeeInstance.salary<0d){
                        employeeInstance.errors.rejectValue( "salary","employee.salary.is.not", "The Salary should be between 0 and 999 999.")
                        wrong=1
                    } }
                //percentageWork
                 if(!employeeInstance.percentageWork){
                        employeeInstance.errors.rejectValue( "percentageWork","employee.percentageWork.is.empty", "Percentage Work should be specified.")
                      wrong=1
                    }
                    else{
                     if(employeeInstance.percentageWork<0 || employeeInstance.percentageWork>100){
                        employeeInstance.errors.rejectValue( "percentageWork","employee.percentageWork.is.wrong", "Percentage Work should be between 0-100 percent.")
                       wrong=1
                    }}




                    //phoneNumber
                     if(employeeInstance.phoneNumber){
                 
                         if(!(employeeInstance.phoneNumber.matches("[0-9 ]+"))){
                        employeeInstance.errors.rejectValue( "phoneNumber","employee.phoneNumber.is.empty", "The Phone Number should only include numbers.")
                        wrong=1
                    }
                }


                    ////to here own constraints
                    if(wrong==1){
                      render(view:'edit',model:[employeeInstance:employeeInstance] )
                    }
                   else {
                  DBConnection.updateEmployee(employeeInstance)
                    session.modified = true // to show popup window
                    flash.message = "Employee ${employeeInstance} updated in sandbox"
                    redirect(action:show,id:employeeInstance.id)
                }}
                else {
                    render(view:'edit',model:[employeeInstance:employeeInstance])
                }
            }
            else{
                if(params.version) {
                    def version = params.version.toLong()
                    if(employeeInstance.version > version) {

                        employeeInstance.errors.rejectValue("version", "employee.optimistic.locking.failure", "Another user has updated this Employee while you were editing.")
                        render(view:'edit',model:[employeeInstance:employeeInstance])
                        return
                    }
                }
                employeeInstance.properties = params
                if(!employeeInstance.hasErrors() && employeeInstance.save()) {
                    flash.message = "Employee ${employeeInstance} updated"
                    redirect(action:show,id:employeeInstance.id)
                }
                else {
                    render(view:'edit',model:[employeeInstance:employeeInstance])
                }
            }

        } //employeeinstance
        else {
            flash.message = "Employee not found"
            redirect(action:list)
        }
    }

    def create = {
        def access = session.access
        access.refresh()
        if(access.checkAccess(session.mode, "employee", "create", null)){
            def employeeInstance = new Employee()
            employeeInstance.properties = params
            return ['employeeInstance':employeeInstance, areaList:access.getList("area")]
        }
        else{
            flash.message = "Missing privilege for this action!"
            redirect(action:list)
        }
    }

    def save = {
         //Check that date of birth is correct
        if(params.dob_month.equals("4")||params.dob_month.equals("6")||params.dob_month.equals("9")||params.dob_month.equals("11")){
            if(params.dob_day.equals("31")){
                    params.dob_month = "ab"
            }
        }

        if(params.dob_month.equals("2")){ // check february month
            if(params.dob_day.equals("31")||params.dob_day.equals("30")){
                    params.dob_month = "ab"
            }
        }

        if(params.mode.equalsIgnoreCase("budget")){
            params.mode=0
        }
        else{
            params.mode=1
        }

        def employeeInstance = new Employee(params)

        if(!employeeInstance.hasErrors()) {
            if(DBConnection.isConnectionStarted()) { // Sandbox mode
                //here for constraints
                Integer wrong=0

                //id
                if(!employeeInstance.employeeId){
                    employeeInstance.errors.rejectValue("employeeId","employee.employeeId.is.empty", "The employeeId should be specified.")
                    wrong=1
                }
                else{
                        if(!(params.employeeId.matches("[0-9 ]+"))){//not working
                        employeeInstance.errors.rejectValue("employeeId","employee.employeeId.is.wrong", "EmployeeId should only include numbers.")
                        wrong=1
                    }
                }
                //firstName
                if(!employeeInstance.firstName){
                  employeeInstance.errors.rejectValue("firstName","employee.firstname.is.empty", "The First Name should be specified.")
                   wrong=1
                }
                else{
                    if(!(employeeInstance.firstName.matches("[a-öA-Ö ]+"))){//Ö
                        employeeInstance.errors.rejectValue("firstName","employee.firstname.is.wrong", "The First Name should only include characters from a-ö.")
                        wrong=1
                    }
                }
                //lastName
                if(!employeeInstance.lastName){
                    employeeInstance.errors.rejectValue("lastName" ,"employee.lastname.is.empty", "The Last Name should be specified.")
                    wrong=1
                }
                else{
                    if(!(employeeInstance.lastName.matches("[a-öA-Ö ]+"))){//Ö  employeeInstance.firstName =~ /[a-öA-Ö ]/
                        employeeInstance.errors.rejectValue("lastName","employee.lastName.is.wrong", "The Last Name should only include characters from a-ö.")
                        wrong=1
                    }
                }
                //street
                if(!employeeInstance.street){
                    employeeInstance.errors.rejectValue( "street","employee.street.is.empty", "The Street should be specified.")
                    wrong=1
                }
                else{
                    if(!employeeInstance.street.matches("[a-öA-Ö0-9 ]+")){//Ö
                        employeeInstance.errors.rejectValue("street","employee.street.is.wrong", "The Street should only include characters from a-ö.")
                        wrong=1
                    }
                }
                //city
                if(!employeeInstance.city){
                        employeeInstance.errors.rejectValue( "city","employee.city.is.empty", "The City should be specified.")
                        wrong=1
                }
                else{
                    if(!employeeInstance.city.matches("[a-öA-Ö]+")){//Ö
                        employeeInstance.errors.rejectValue("city","employee.city.is.wrong", "The City should only include characters from a-ö.")
                        wrong=1
                    }
                }
                //zipCode
                if(!employeeInstance.zipCode){
                    employeeInstance.errors.rejectValue( "zipCode","employee.zipCode.is.empty", "The Zip Code should be specified.")
                     wrong=1
                }
                    else{
                     if(employeeInstance.zipCode<10000 || employeeInstance.zipCode>99999){
                        employeeInstance.errors.rejectValue( "zipCode","employee.zipCode.is.not", "The Zip Code is not correct.")
                        wrong=1
                    }}
                //DOB
                if(employeeInstance.dob>new Date()){
                    employeeInstance.errors.rejectValue("dob" ,"employee.dop.is.not", "The date of birth is not correct.")
                    wrong=1
                }
                //email
                if(!employeeInstance.email){
                    employeeInstance.errors.rejectValue("email" ,"employee.email.is.empty", "The Email should be specified.")
                    wrong=1
                }
                else{
                    if(!employeeInstance.email.matches("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}")){//Ö
                        employeeInstance.errors.rejectValue("email" ,"employee.email.wrong", "The Email is not correct.")
                        wrong=1
                    }
                }
                    //title
                if(!employeeInstance.title){
                    employeeInstance.errors.rejectValue( "title","employee.title.is.empty", "The Title should be specified.")
                    wrong=1
                }
                //salary
                if(!employeeInstance.salary){
                    employeeInstance.errors.rejectValue( "salary","employee.salary.is.empty", "The Salary should be specified.")
                    wrong=1
                }
                else{
                    if(employeeInstance.salary<0d){
                        employeeInstance.errors.rejectValue( "salary","employee.salary.is.not", "The Salary should be between 0 and 999 999.")
                        wrong=1
                    }
                }
                //percentageWork
                if(!employeeInstance.percentageWork){
                    employeeInstance.errors.rejectValue( "percentageWork","employee.percentageWork.is.empty", "Percentage Work should be specified.")
                    wrong=1
                }
                else{
                    if(employeeInstance.percentageWork<0 || employeeInstance.percentageWork>100){
                        employeeInstance.errors.rejectValue( "percentageWork","employee.percentageWork.is.wrong", "Percentage Work should be between 0-100 percent.")
                        wrong=1
                    }
                }
                //phoneNumber
                if(employeeInstance.phoneNumber){
                    if(!(employeeInstance.phoneNumber.matches("[0-9 ]+"))){
                        employeeInstance.errors.rejectValue( "phoneNumber","employee.phoneNumber.is.empty", "The Phone Number should only include numbers.")
                        wrong=1
                    }
                }
                if(wrong==1){
                    render(view:'create',model:[employeeInstance:employeeInstance])
                }
                else{
                    Integer idE
                    if((idE=DBConnection.saveEmployee(employeeInstance))>0){
                        session.modified = true // to show popup window
                        flash.message = "Employee ${employeeInstance} created in sandbox"
                        redirect(action:show,id:idE)
                    }
                    else{
                        if(idE==-2){
                            employeeInstance.errors.rejectValue("employeeId","employee.employeeId.is.not.unique", "The EmployeeId should be unique.")
                            render(view:'create',model:[employeeInstance:employeeInstance])
                        }
                        render(view:'create',model:[employeeInstance:employeeInstance])
                    }
                }
            }// end sandbox mode checks
            else{
                if(employeeInstance.save()){
                flash.message = "Employee ${employeeInstance} created"
                redirect(action:show,id:employeeInstance.id)
                }
                else{
                    render(view:'create',model:[employeeInstance:employeeInstance])
                }
            }
        }// end no errors
        else{ //has errors
            render(view:'create',model:[employeeInstance:employeeInstance])
        }
    }

   def updateFigures = {
        Float newFigure = Float.parseFloat(params.figure);

        def employeeInstance
        
        if(DBConnection.isConnectionStarted()){
            employeeInstance = DBConnection.getEmployee(params.id);   // The ID from javascript (that comes from show)
        }
        else{
            employeeInstance = Employee.get(params.id);
        }
        def ajaxCall = params.ajaxCall;

        if(params.type == "percentageWork"){
            if(newFigure<0 || newFigure>100){
            }
            else{
                employeeInstance.percentageWork = newFigure;
            }
        }
        else if (params.type == "hoursWork") {
           /*   if( newFigure>employeeInstance.getWorkingHoursPerYear()|| newFigure<0){
                  flash.message = "Workhours is wrong"
                  redirect(action:blank);
                 }*/
            employeeInstance.percentageWork = employeeInstance.updateWorkPercentageWithHours(newFigure)
        }
        else if (params.type == "percentageWorkUpArrow") {
            
            employeeInstance.percentageWork = employeeInstance.arrowUp()
        }
        else if (params.type == "percentageWorkDownArrow"){
          
            employeeInstance.percentageWork = employeeInstance.arrowDown()
        }
        else{
           //  b.knownTotalIncome = newIncome;
        }
        if(DBConnection.isConnectionStarted()){
     
            DBConnection.updateEmployee(employeeInstance);
            session.modified = true // to show popup window

        }
        else{
            if(employeeInstance.isWorkingOverTime()){
                println("OVERBOOKED!!!")
            }
            else{
                employeeInstance.save(flush:true);
            }
        }
        /*
        if(employeeInstance.save(flush:true)){ // save method is an boolean
            println("saved motherfucker!");
        }
        else{
             employeeInstance.errors.each {
                  println(it);
                }
                
        }
        */

        redirect(controller:"employee", action:show, params:[id: employeeInstance.id,ajaxCall:ajaxCall]);

    }

    def application = {

         //constraints
        if(params.checkErrorId.equals("checkErrorApplication")){
            def employeeInstance =new Employee()
            Integer wrong=0
            if(!params.employeeId){
                       employeeInstance.errors.rejectValue("employeeId","employee.civic.is.empty", "Personnummer should be specified.")
                        wrong=1

            }
             else{
                if(!(params.employeeId.matches("[0-9 ]+"))){//not working
                    employeeInstance.errors.rejectValue("employeeId","employee.civic.is.wrong", "Personnummber should only include numbers.")
                    wrong=1

                }
            }
            params.checkErrorId=null
            if(wrong==1){
                render(view:'application',params:[employeeId:params.employeeId])
            }
            else{
                redirect(action:'checkCivicNumber',params:[employeeId:params.employeeId])
            }
        }


    render(view:'application',params:[employeeId:params.employeeId])
        }

    def checkCivicNumber={
      

        def employeeInstance = Employee.findByEmployeeId(params.employeeId)
        //if not exists
        if(!employeeInstance || employeeInstance.firstName.equals("non")){
            redirect(action:'createApplicant',params:[employeeId:params.employeeId])
        }
        //if exists
        else{
            redirect(action:'applicationEmployee',params:[employeeId:params.employeeId])
        }
    }
        def applicationEmployee = {
         
            def employeeInstance= Employee.findByEmployeeId(params.employeeId)
             return [employeeInstance:employeeInstance]
      //render(view:'applicationEmployee',model:[employeeInstance:employeeInstance])
        }

    def createApplicant={
        //create new one because otherwise there is a problem with employeeId being unique
        def employeeInstance = Employee.findByEmployeeId(params.employeeId)

        if(!employeeInstance){
             employeeInstance = new Employee(params)

                //has to check firstName//lastName// title// email//
           //firstName
              employeeInstance.firstName="non"
              employeeInstance.lastName="non"
              employeeInstance.title="non"
              employeeInstance.email="non@non.non"

             // employee.hiredby nullable
              employeeInstance.mode=3 //ok??
              employeeInstance.street="no street "
              employeeInstance.city="no city "
              employeeInstance.zipCode=10000
              employeeInstance.dob=new Date() //can be null
              employeeInstance.dob.setDate(employeeInstance.dob.getDate()-1);
              employeeInstance.salary=1
              employeeInstance.percentageWork=1 //can be null
              employeeInstance.isApplicant=true
             employeeInstance.save(flush:true)
        }
          redirect(action:'applicationApplicant',params:[employeeId:params.employeeId])

    }
         def applicationApplicant = {
  
            def employeeInstance = Employee.findByEmployeeId(params.employeeId)
            Integer wrong=0
        if(params.checkErrorId.equals("checkErrorId")){
             ///check constraints
                    if(!params.firstName){
                      employeeInstance.errors.rejectValue("firstName","employee.firstname.is.empty","The First Name should be specified.")
                       employeeInstance.firstName="non"
                      wrong=1
                    }
                    else{
                        if(!(params.firstName.matches("[a-öA-Ö ]+"))){//Ö 
                    employeeInstance.errors.rejectValue("firstName","employee.firstname.is.wrong", "The First Name should only include characters from a-ö.")
                    wrong=1}
                    employeeInstance.firstName=params.firstName
                      }

                       //lastName

                    if(!params.lastName){
                        employeeInstance.errors.rejectValue("lastName" ,"employee.lastname.is.empty", "The Last Name should be specified.")
                         employeeInstance.lastName="non"
                        wrong=1
                    }
                     else{
                        if(!(params.lastName.matches("[a-öA-Ö ]+"))){//Ö  employeeInstance.firstName =~ /[a-öA-Ö ]/
                      employeeInstance.errors.rejectValue("lastName","employee.lastName.is.wrong", "The Last Name should only include characters from a-ö.")
                  wrong=1}
                      employeeInstance.lastName=params.lastName

                    }
             //email
                     if(!params.email){
                         employeeInstance.email="non@non.non"
                    }
                    else{
                    if(!params.email.matches("[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}")){//Ö
                           employeeInstance.errors.rejectValue("email" ,"employee.email.wrong", "The Email is not correct.")
                       wrong=1
                    }
                          employeeInstance.email=params.email
                    }
                    //title
                     if(!params.title){
                        employeeInstance.title="non"
                    }
                    else{
                        employeeInstance.title=params.title
                    }
                    if(wrong==1){
                        params.checkErrorId=null
                        render(view:'applicationApplicant', model:[employeeInstance:employeeInstance])//model:[employeeInstance:employeeInstance]
                    }
                    else{
                        params.checkErrorId=null
                        redirect(action:'applicationFinished', params:params)
                    }
        }  //constraints

             return [employeeInstance:employeeInstance ]
        }
        
    

    def applicationFinished={
        Integer wrong=0
        def employeeInstance = Employee.findByEmployeeId(params.employeeId)
     
        ///check constraints
                    

        def scheduleInstance = Schedule.get(params.scheduleId)
        /*participation create and saves*/
        def participationsInstance=new Participations(participant:employeeInstance, schedule:scheduleInstance)
        participationsInstance.bankAccount=params.bankAccount
        participationsInstance.faculty=params.faculty
        participationsInstance.department=params.department
        participationsInstance.division=params.division
        participationsInstance.billingAdress=params.billingAdress
        participationsInstance.lukasId=params.lukasId

                if(!participationsInstance.hasErrors() && participationsInstance.save()) {
           //flash.message = "Participations ${participationsInstance.id} created"
             return [employeeId:params.employeeId,scheduleId:params.scheduleId]
        }
        else {
                 if(params.applicationId.equals("applicationEmployee")){
          redirect(action:'applicationEmployee',params:params)}
          else{
               redirect(action:'applicationApplicant',params:params)
          }
        }
        }



        def sendCourse={
          
            def employeeInstance= Employee.findByEmployeeId(params.employeeId)
            if(params.courseId.equals("null")) params.courseId=null
            if(params.applicationId.equals("applicationEmployee")){
                render(view:'applicationEmployee',model:[employeeInstance:employeeInstance],params:params)}
            else{
                render(view:'applicationApplicant',model:[employeeInstance:employeeInstance],params:params)
            }
        }



        def sendSchedule={
            def employeeInstance= Employee.findByEmployeeId(params.employeeId)

            if(params.applicationId.equals("applicationEmployee")){
        render(view:'applicationEmployee',model:[employeeInstance:employeeInstance],params:params)}
            else{
                render(view:'applicationApplicant',model:[employeeInstance:employeeInstance],params:params)
            }
        }


    def blank = {}
}
